package com.somsoft.unlockme.db;

import com.somsoft.unlockme.fk.C;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBOpenHelper extends SQLiteOpenHelper {

	private String createTableSql = "create table t_level("+
			"level integer primary key,"+
			"isLock varchar(1),"+
			"score integer,"+
			"isGetScore varchar(1),"+
			"step integer,"+
			"best integer,totalScore integer)";
	
	public DBOpenHelper(Context context) {
		super(context, "unlockme.db", null, 1);//数据库版本号改变，将会执行onUpgrade方法
	}

	@Override
	public void onCreate(SQLiteDatabase db) {//第一次使用时执行的方法
//		db.execSQL("create table person(id integer primary key autoincrement,name varchar(20),phone varchar(20))");
		db.execSQL(createTableSql);
		db.execSQL("insert into t_level(level,isLock,score,isGetScore,step,best,totalScore) values(?,?,?,?,?,?,?) ",
				new Object[]{1,"N",0,"N",0,0,0});
		for(int i=2;i<=C.MAX_LEVEL;i++){
			db.execSQL("insert into t_level(level,isLock,score,isGetScore,step,best,totalScore) values(?,?,?,?,?,?,?) ",
					new Object[]{i,"Y",0,"N",0,0,0});
		}
		Log.i("创建数据库=====", "创建数据库=====");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//		db.execSQL("alter table person add amount int(10)");
		Log.i("更新数据库=====", "更新数据库=====");
	}

}